package com.ztil.socket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
	private ServerSocket _serverSocket;
	private Socket _clientSocket;

	public static void main(String[] args) {
		Server s = new Server();
		s.start(8888);
	}

	public void start(int port) {
		try {
			_serverSocket = new ServerSocket(port);
			System.out.println("Start ServerSocket At : [" + _serverSocket.getLocalSocketAddress() + "]");
			while (_serverSocket.isBound()) {
				_clientSocket = _serverSocket.accept();
				System.out.println("Receive Client : [" + _clientSocket.getRemoteSocketAddress() + "]");
				_clientSocket.setKeepAlive(true);
				SocketHandler handler = new SocketHandler();
				handler.hand(_clientSocket);
				handler.read();
//				handler.write(msg);
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
